package com.lemei.cn.myokhttpbeen.viewholder;

import android.text.format.Formatter;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lemei.cn.myokhttpbeen.GoogleApp;
import com.lemei.cn.myokhttpbeen.R;
import com.lemei.cn.myokhttpbeen.been.HomeItem;

/**
 * Created by 赵航 on 2017/6/11.
 */

public class HomeViewHolder extends BeasicViewHolder<HomeItem.HomeItemBeen> {
    ImageView ivHomeIcon;
    RatingBar rbHomeStart;
    TextView  tvHomeTitle;
    TextView  tvHomeSize;
    TextView  tvHomeDesc;
    private View mView;


    //布局
    @Override
    public View getItemView() {
        mView = View.inflate(GoogleApp.context, R.layout.item_home, null);

        ivHomeIcon = (ImageView) mView.findViewById(R.id.iv_home_icon);
        tvHomeTitle = (TextView) mView.findViewById(R.id.tv_home_title);
        rbHomeStart = (RatingBar) mView.findViewById(R.id.rb_home_start);
        tvHomeSize = (TextView) mView.findViewById(R.id.tv_home_size);
        tvHomeDesc = (TextView) mView.findViewById(R.id.tv_home_desc);


        return mView;
    }
    //数据
    @Override
    public void bindView(HomeItem.HomeItemBeen items) {

        tvHomeTitle.setText(items.getName());

        //显示文件大小友好化
        String fileSize = Formatter.formatFileSize(GoogleApp.context, items.getSize());
        tvHomeSize.setText(fileSize);
        tvHomeDesc.setText(items.getDes());

        rbHomeStart.setRating(items.getStars());
        //
        //        DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(R.mipmap.ic_launcher) //显示图片加载中
        //                .showImageForEmptyUri(R.mipmap.ic_launcher) //空的图片
        //                .showImageOnFail(R.mipmap.ic_launcher) //错误的图片
        //                .cacheInMemory(true) //内存缓存要不要
        //                .cacheOnDisk(true) //sd卡缓存要不要
        //                .considerExifParams(true)//会识别图片的方向信息
        //                .displayer(new FadeInBitmapDisplayer(500)).build();//显示的效果
        //        //		.displayer(new RoundedBitmapDisplayer(36)).build();
        //
        //        //设置图片
        //        ImageLoader.getInstance().displayImage("http://127.0.0.1:8090/image?name="+items.getIconUrl(), ivHomeIcon, options);
        //
        Glide.with(GoogleApp.context)
                .load("http://127.0.0.1:8090/image?name=" + items.getIconUrl())
                .placeholder(R.mipmap.ic_launcher)
                .crossFade()
                .into(ivHomeIcon);
    }

}

